package com.su.ou.yang;

import java.nio.channels.NonReadableChannelException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;

public class Test12 {
    public static void main(String[] args) {
        Test4.TreeNode node1 = new Test4.TreeNode(1);
        Test4.TreeNode node2 = new Test4.TreeNode(2);
        Test4.TreeNode node3 = new Test4.TreeNode(2);
        Test4.TreeNode node4 = new Test4.TreeNode(4);
        Test4.TreeNode node5 = new Test4.TreeNode(4);
        node1.left=node2;
        node1.right=node3;
       node2.left=node4;
       node3.right=node5;
        System.out.println(solve(node1));

    }

    public  static boolean solve(Test4.TreeNode root) {
        if (root == null) {
            return false;
        }
        return  IsDuiChen(root.left, root.right);

    }

    private  static Boolean IsDuiChen(Test4.TreeNode left, Test4.TreeNode right) {
        if(left==null&&right!=null){
            return false;
        }
        if(left!=null&&right==null){
            return false;
        }
        if (left==null&&right==null){
            return true;
        }
        if (left.val == right.val) {
            return IsDuiChen(left.left, right.right) && IsDuiChen(left.right, right.left);
        }

        return false;

    }
}
